//
//  WithdrawSecondMoneyCell.m
//  GasBusiness
//
//  Created by zfc on 2021/8/1.
//

#import "WithdrawSecondMoneyCell.h"

@interface WithdrawSecondMoneyCell ()

@property (nonatomic, strong) UILabel *moneyLab;
@end

@implementation WithdrawSecondMoneyCell

- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)setUI {

    self.contentView.backgroundColor = ColorF5;
    UIView *backView = [[UIView alloc] init];
    backView.backgroundColor = WhiteColor;
    [self.contentView addSubview:backView];
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.contentView);
        make.leading.equalTo(self.contentView);
        make.top.equalTo(self.contentView);
    }];

    UILabel *lab = [[UILabel alloc] init];
    lab.text = @"提现金额：";
    lab.font = [UIFont systemFontOfSize:12 weight:UIFontWeightBold];
    lab.textColor = Color333;
    [backView addSubview:lab];
    [lab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(backView).offset(15);
        make.top.equalTo(backView).offset(15);
    }];

    UIView *lineView = [[UIView alloc] init];
    lineView.backgroundColor = ColorF5;
    [backView addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.equalTo(self.contentView);
        make.height.mas_equalTo(1);
        make.bottom.equalTo(backView).offset(-38);
        make.top.equalTo(backView).offset(84);
    }];

    UILabel *tagLab = [[UILabel alloc] init];
    tagLab.text = @"¥";
    tagLab.textColor = Color333;
    tagLab.textAlignment = NSTextAlignmentCenter;
    tagLab.font = [UIFont systemFontOfSize:24 weight:UIFontWeightBold];
    [backView addSubview:tagLab];
    [tagLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(lineView.mas_top).offset(-15);
        make.leading.equalTo(backView).offset(15);
    }];

    UITextField *moneyTf = [[UITextField alloc] init];
    NSAttributedString *moneyAttr = [[NSAttributedString alloc] initWithString:@"请输入提现金额" attributes:
    @{NSForegroundColorAttributeName:Color999,
      NSFontAttributeName:[UIFont systemFontOfSize:14 weight:UIFontWeightBold]
    }];
    moneyTf.attributedPlaceholder = moneyAttr;
    moneyTf.text = @"";
    moneyTf.keyboardType = UIKeyboardTypeDecimalPad;
    [backView addSubview:moneyTf];
    self.moneyTf = moneyTf;
    [moneyTf mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(backView).offset(40);
        make.centerY.equalTo(tagLab);
        make.trailing.equalTo(backView).offset(-15);
        make.height.mas_equalTo(45);
    }];


    UILabel *moneyLab = [[UILabel alloc] init];
    moneyLab.text = @"当前余额0.00元,";
    moneyLab.textColor = Color999;
    moneyLab.font = [UIFont systemFontOfSize:12 weight:UIFontWeightMedium];
    [backView addSubview:moneyLab];
    self.moneyLab = moneyLab;
    [moneyLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lineView.mas_bottom).offset(10);
        make.leading.equalTo(backView).offset(15);
    }];

    UIButton *totalWithdrawBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [totalWithdrawBtn setTitle:@"全部提现" forState:UIControlStateNormal];
    [totalWithdrawBtn setTitleColor:[UIColor colorWithHexString:@"3D6DCC"] forState:UIControlStateNormal];
    totalWithdrawBtn.titleLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightBold];
    [backView addSubview:totalWithdrawBtn];
    [totalWithdrawBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(moneyLab);
        make.leading.equalTo(moneyLab.mas_trailing);
    }];

    WeakSelf;
    totalWithdrawBtn.block = ^(UIButton *sender) {
        weakSelf.moneyTf.text =  [NSString stringWithFormat:@"%.2f", [weakSelf.dic[@"user_money"] floatValue] - [weakSelf.dic[@"frozen_money"] floatValue]];;
    };

}

- (void)setDic:(NSDictionary *)dic {
    _dic = dic;
    self.moneyLab.text = [NSString stringWithFormat:@"当前余额%.2f元,", [dic[@"user_money"] floatValue] - [dic[@"frozen_money"] floatValue]];
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}

@end
